package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/setmeal")
@Api(tags = "管理端端-套餐浏览接口")
public class SetAdminMealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 新增套餐
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增套餐")
    @PostMapping
    public Result add(@RequestBody SetmealDTO dto) {
        log.info("新增套餐:{}", dto);
        setmealService.add(dto);
        return Result.success();
    }

    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(SetmealPageQueryDTO dto) {
        log.info("分页查询：{}", dto);
        PageResult pageResult = setmealService.page(dto);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询套餐
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<Setmeal> selectById(@PathVariable Long id) {
        log.info("根据id查询套餐：{}", id);
        Setmeal setmeal = setmealService.selectById(id);
        return Result.success(setmeal);
    }

    /**
     * 删除套餐
     *
     * @param ids
     * @return
     */
    @PutMapping
    @ApiOperation("删除套餐")
    public Result deleteByIds(@RequestParam List<Long> ids) {
        log.info("删除套餐：{}", ids);
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 修改套餐
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("修改套餐")
    public Result update(@RequestParam SetmealDTO dto){
        setmealService.update(dto);
        return Result.success();
    }
    /**
     * 套餐起售停售
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("套餐起售停售")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        setmealService.startOrStop(status, id);
        return Result.success();
    }
}
